package com.shuma.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuma.auth.model.dto.ProxyUserInfoDto;
import com.shuma.auth.model.dto.QueryProxyUserParams;
import com.shuma.auth.model.po.UserProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 管理人（运营或代理人）和商品的关联 Mapper 接口
 * </p>
 *
 * @author lele
 */
@Mapper
public interface UserProductMapper extends BaseMapper<UserProduct> {

    /**
     * SELECT up.product_id
     * FROM user u
     * inner JOIN user_product up
     * ON u.id = up.user_id
     * WHERE u.username LIKE '%u%'
     * @param caretaker
     * @return
     */
    @Select("SELECT product_id \n" +
            "FROM user_product \n" +
            "WHERE username LIKE '#{caretaker}' and level = 0")
    List<Long> selectProductIdsByUsername(String caretaker);


    /**
     * SELECT  u.id,up.level
     * FROM user u
     * inner JOIN user_product up
     * ON u.id = up.user_id
     * WHERE u.id=1 AND up.product_id=1
     */
    @Select("SELECT  up.level\n" +
            "FROM user u\n" +
            "inner JOIN user_product up\n" +
            "ON u.id = up.user_id\n" +
            "WHERE u.id=#{userId} AND up.product_id=#{ProductId}")
    Integer isManager(Long userId,Long ProductId);


    /**
     * SELECT u.id,u.username
     * FROM user u
     * WHERE
     * u.username LIKE CONCAT('%','x','%')
     * and u.role_id = 1
     * AND u.id not IN
     * (SELECT user_id
     * FROM user_product
     * WHERE product_id = 1
     * )
     * @return
     */
    List<ProxyUserInfoDto> selectProxyUserByUsername(QueryProxyUserParams queryProxyUserParams);
}
